<template>
  <div class="app-container">
    <!--搜索数据-->
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="申请人" prop="applyUser">
        <el-input
          v-model="queryParams.applyUser"
          placeholder="请输入申请人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请日期" prop="applyDate">
        <el-date-picker
          v-model="queryParams.applyDate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="请选择日期"
          size="small"
          @keyup.enter.native="handleQuery"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="申请部门" prop="applyDept">
        <el-input
          v-model="queryParams.applyDept"
          placeholder="请输入申请部门"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="24" class="mb8">
      <el-col class="table-title-panel">
        <span class="table-title">变更审批列表</span>
        <div style="float:right;"></div>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="tableData"
      :max-height="tableHeight"
    >
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="申请人" align="center" prop="applyUser" :show-overflow-tooltip="true" />
      <el-table-column label="申请日期" align="center" prop="applyDate" :show-overflow-tooltip="true" />
      <el-table-column label="申请部门" align="center" prop="applyDept" :show-overflow-tooltip="true" />
      <el-table-column label="变更类型" align="center" prop="type" :show-overflow-tooltip="true" />
      <el-table-column label="变更所属区域" align="center" prop="area" :show-overflow-tooltip="true" />
      <el-table-column label="变更前" align="center" prop="changeBefore" :show-overflow-tooltip="true" />
      <el-table-column label="变更后" align="center" prop="changeAfter" :show-overflow-tooltip="true" />
      <el-table-column label="变更完成情况" align="center" prop="completeState" :show-overflow-tooltip="true" />
      <el-table-column label="部门领导审核" align="center" prop="examState" :show-overflow-tooltip="true" />
      <el-table-column
        label="操作"
        align="center"
        width="220"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleEdit(scope.row, false)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <change-form ref="changeForm" v-model="open" :editable="editable" :title="title" @submitSuccess="getList"></change-form>
  </div>
</template>

<script>
import { list, del } from "@/api/modules/process/change/list";
import ChangeForm from "@/views/components/process/change/change-form";

export default {
  components: {
    ChangeForm
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: '添加',
      // 是否可编辑
      editable: true,
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        applyUser: undefined,
        applyDate: undefined,
        applyDept: undefined
      }
    };
  },
  computed: {
    /** 主表高度 */
    tableHeight() {
      return this.$store.state.common.tableHeight;
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询主列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        const result = response.result;
        this.tableData = result.list;
        this.total = result.totalCount;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 编辑按钮操作 */
    handleEdit(row, editable) {
      this.open = true;
      this.editable = editable;
      this.title = editable ? '编辑' : '查看';
      this.$nextTick(() => {
        this.$refs.changeForm.setup({...row});
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.right-title span {
  padding-left: 20px;
  font-size: 14px;
}
</style>